package src.leetcode.everyday.simple_1103;

import java.util.Arrays;

public class distributeCandies {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(Arrays.toString(solution.distributeCandies(7, 4)));
    }
}


class Solution {
    public int[] distributeCandies(int candies, int num_people) {
        int[] ans = new int[num_people];
        int i = 0, j = 1;
        while (candies > 0) {
            if (candies - j >= 0) {
                ans[i] += j;
                candies -= j;
                j++;
            } else {
                ans[i] += candies;
                candies = 0;
            }
            i = (i + 1) % num_people;
        }
        return ans;
    }
}